import orderApi from 'api/order'

// state
let state = {
  list: {
    params: {}, // 获取参数
    data: {} // 分页数据
  },
  detail: {}, // 获取订单详情
  amount: 0, // 获取订单金额
  getData: {}  // 传递url中参数
}

// getters
const getters = {
  order_list: state => state.list,
  order_detail: state => state.detail,
  order_amount: state => state.amount,
  order_update_url: state => state.getData
}

// actions
const actions = {
  order_list ({ commit, state }, params) {
    orderApi.list(params).then((json) => {
      commit('ORDER_LIST', {
        params: params,
        data: json.data
      })
    })
  },
  order_detail ({ commit, state }, params) {
    orderApi.detail(params).then((json) => {
      commit('ORDER_DETAIL', {
        params: params,
        data: json.data
      })
    })
  },
  order_amount ({ commit, state }, params) {
    orderApi.amount(params).then((json) => {
      commit('ORDER_AMOUNT', {
        params: params,
        data: json.data
      })
    })
  },
  order_update_url ({commit}, params) {
    console.log(arguments)
    commit('ORDER_UPDATE_URL', params)
  }
}
// mutations
const mutations = {
  ORDER_LIST (state, { data, params }) {
    state.list = data
  },
  ORDER_DETAIL (state, { data, params }) {
    state.detail = data
  },
  ORDER_AMOUNT (state, { data, params }) {
    state.amount = data
  },
  ORDER_UPDATE_URL (state, params) {
    state.getData = params
  }
}

export default {
  state,
  getters,
  actions,
  mutations
}
